package com.xiaofu.controller;


import com.xiaofu.enums.BizCodeEnum;
import com.xiaofu.service.CouponRecordService;
import com.xiaofu.utils.JsonData;
import com.xiaofu.vo.CouponRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小夫
 * @since 2024-07-18
 */
@Api("优惠券记录模块")
@RestController
@RequestMapping("/api/coupon_record/v1")
public class CouponRecordController {

    @Autowired
    private CouponRecordService couponRecordService;


    @ApiOperation("分页查询个人优惠券")
    @GetMapping("page")
    public JsonData page(@ApiParam("当前页") @RequestParam(value = "page", defaultValue = "1") int page,
                         @ApiParam("每页显示多少条") @RequestParam(value = "size", defaultValue = "20") int size) {
        Map<String,Object> pageInfo = couponRecordService.page(page, size);
        return JsonData.buildSuccess(pageInfo);
    }

    @ApiOperation("查询优惠券记录详情")
    @GetMapping("detail/{record_id}")
    public JsonData getCouponRecordDetail(@ApiParam("记录ID") @PathVariable("record_id") Long recordId) {
        CouponRecordVO couponRecordVO = couponRecordService.findById(recordId);
        return couponRecordVO == null ? JsonData.buildResult(BizCodeEnum.COUPON_NO_EXITS):JsonData.buildSuccess(couponRecordVO);
    }

}

